<?
header('Content-type: text/xhtml');

/**
 *	ajax load for modules
 *  used for add pinpoint etc
 *
 * 	extra functions are for merging module vars and parameters vars
 */


/** 
 * 	object to array
 * 	@return		object
 * 	@param		array
 */
function obj_to_array( $data ){
   
    if( !is_object( $data ) && !is_array( $data )) 
    	return $data;
    
    if( is_object( $data )) 
    	$data = get_object_vars( $data );

    return array_map( 'obj_to_array', $data);
}



/** 
 * 	object to array
 * 	@return		array
 * 	@param		object
 */
function arr_to_obj( $data ) {
  
    if( !is_array( $data )) 
    	return $data;

    $object = new stdClass();
    if ( is_array( $data ) && count( $data ) > 0) {
        foreach ( $data as $name=>$value ) {
            $name = strtolower( trim( $name ));
            if ( !empty( $name )) {
                $object->$name = arr_to_obj( $value );
            }
        }
    }
    
    return $object;
}



$Modcon = new MOD_CONSTRUCT();

$set = json_decode( $_POST['set'] );

$Module = $Modcon->call( $set->id );

if( $set->vars )
	$Module->vars = arr_to_obj( array_merge_recursive( obj_to_array( $set->vars ), obj_to_array( $Module->vars )));

echo $Module->output();

?>